require 'lib/utils.rb'
ratings = getRatingsFromFile(ARGV[0]);

$fileName = "ratings-" + (Date.today.to_s) + ".txt";

if(File.exist?($fileName))
	$i = 1;
	$fileName = "ratings-" + (Date.today.to_s) + "-" +  $i.to_s + ".txt";
	while(File.exist?($fileName))
		$i+=1;
		$fileName = "ratings-" + (Date.today.to_s) + "-" +  $i.to_s + ".txt";
	end	
end

$devalvationCoefficient = 1.0

fout = File.new($fileName, "w")
ratings.sort{|a,b| b[1] <=> a[1]}.each {|key, value| 
	if($devalvationCoefficient == 1.0 && value > 900)
	 $devalvationCoefficient = 900.0/value;
	end
	value = value*$devalvationCoefficient
	fout <<  key.to_s + " "*(20 - key.length) + format("%.4f", [value,0.0].max ) + "\n";
}
fout.close

p "Coefficient: " + $devalvationCoefficient.to_s